package org.example.petsystem.controller;

import org.example.petsystem.entity.ResultBody;
import org.example.petsystem.service.ShopMessageBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/ShopMessageBoard")
@CrossOrigin(origins="*")
public class ShopMessageBoardController {
    @Autowired
    private ShopMessageBoardService shopMessageBoardService;

    // 用户留言
    @PostMapping("/addMessage")
    public ResultBody addMessage(@RequestBody Map<String, Object> map) {
        if (map.get("shopPhone") == null || map.get("userPhone") == null || map.get("content") == null) {
            return new ResultBody(400, "参数不完整", false);
        }
        return shopMessageBoardService.addMessage(map);
    }

    // 商家回复
    @PostMapping("/replyMessage")
    public ResultBody replyMessage(@RequestBody Map<String, Object> map) {
        if (map.get("messageId") == null || map.get("shopPhone") == null || map.get("reply") == null) {
            return new ResultBody(400, "参数不完整", false);
        }
        return shopMessageBoardService.replyMessage(map);
    }

    // 获取商家的所有留言
    @PostMapping("/getShopMessages")
    public ResultBody getShopMessages() {

        return shopMessageBoardService.getShopMessages();
    }

    // 获取用户的留言历史
    @PostMapping("/getUserMessages")
    public ResultBody getUserMessages(@RequestBody Map<String, Object> map) {
        if (map.get("userPhone") == null) {
            return new ResultBody(400, "参数不完整", false);
        }
        return shopMessageBoardService.getUserMessages(map);
    }

    // 获取未回复的留言数量
    @PostMapping("/getUnreplied")
    public ResultBody getUnreplied() {

        return shopMessageBoardService.getUnreplied();
    }
} 